#include<bits/stdc++.h>
using namespace std;
int T,n,ans,a[200001];
bool v[1000001];
inline void dfs(int k,int q,int w,int sum){
    if(k==n+1){
        ans=max(ans,sum);
        return;
    }
    if(a[k]==a[q]){
        dfs(k+1,k,w,sum+a[k]);
        dfs(k+1,q,k,sum);
    }
    else if(a[k]==a[w]){
        dfs(k+1,q,k,sum+a[k]);
        dfs(k+1,k,w,sum);
    }

    else{
        dfs(k+1,k,w,sum);
        dfs(k+1,q,k,sum);
    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        ans=0;
        memset(v,0,sizeof(v));
        bool op=1;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            if(v[a[i]])op=0;
            v[a[i]]=1;
        }
        if(op)
        {
            printf("0\n");
            continue;
        }
        dfs(1,-1,-1,0);
        printf("%d\n",ans);
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
